
#include "main.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"


gpio_config_t io_conf;
int a = 1;
static const char *TAG = "led_flash";
void ledIoInit()
{
    //禁用中断
    io_conf.intr_type = GPIO_INTR_DISABLE;
    //set as output mode
    io_conf.mode = GPIO_MODE_OUTPUT;
    //设置bitmap，用来控制当前设置的是哪个引脚，bit为为1的就是当前要设置的引脚
    io_conf.pin_bit_mask = GPIO_LED_BIT;
    //disable pull-down mode
    io_conf.pull_down_en = 0;
    //disable pull-up mode
    io_conf.pull_up_en = 0;
    //configure GPIO with the given settings
    gpio_config(&io_conf);
}

void ledClose()
{
    gpio_set_level(GPIO_LED, 1);  
}

void ledOpen()
{
    gpio_set_level(GPIO_LED, 0);  
}

void flash() 
{
    while (1)
    {
        if (isInit()) {
            ESP_LOGI(TAG, "end flash");
            ledClose();
            break;
        }
        if (a) {
            ledOpen();
            a = 0;
        } else {
            ledClose();
            a = 1;
        }
        vTaskDelay(50);
    }
    vTaskDelete(NULL);
}

void ledFlash()
{
    ESP_LOGI(TAG, "begin ledFlash");
    ledIoInit();
    xTaskCreate(flash, 
        "led_flash",
        1024*2,
        NULL,
        20,
        NULL);
}

